<?php
class Zendvn_System_Cache {
	
	protected $_frontendOptions = array(
		   'lifetime' => 7200, // cache lifetime of 2 hours
		   'automatic_serialization' => true,
	);
		 
	protected $_backendOptions = array(
			'cache_dir' 	=> CACHE_PATH, // Directory where to put the cache files
			'compression'	=> true
			//'servers' => array(
			//	array('host' => '127.0.0.1', 'port' => 11211)
			//),
			//'compression' => true
	);
	
	protected $_cache;
	
	public function __construct()
	{
		// getting a Zend_Cache_Core object
		$this->_cache = Zend_Cache::factory('Core', 'File', $this->_frontendOptions, $this->_backendOptions);
		//$this->_cache = Zend_Cache::factory('Core', 'Memcached', $this->_frontendOptions, $this->_backendOptions);
	}
	
	public function load($data)
	{
		return $this->_cache->load($data);
	}
	
	public function save($data, $name)
	{
		return $this->_cache->save($data, $name);
	}
	
	public function clean($data = array())
	{
		if ( ! empty($data))
		{
			$this->_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $data);
		}
		else
		{
			$this->_cache->clean(Zend_Cache::CLEANING_MODE_ALL);
		}
		return $this;
	}
	
	public function remove($id)
	{
		return $this->_cache->remove($id);
	}
}